package com.junzhiit.nengji.shop.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.bainaeco.framework.base.dao.AbstractBaseDAO;
import com.bainaeco.framework.common.jdbc.StatementParameter;
import com.bainaeco.framework.enums.IsDelete;
import com.junzhiit.nengji.shop.dao.ChainSkuItemsDAO;
import com.junzhiit.nengji.shop.model.ChainSkuItems;
import com.junzhiit.nengji.shop.model.SkuItems;

@Repository
public class ChainSkuItemsDAOImpl extends AbstractBaseDAO<ChainSkuItems> implements ChainSkuItemsDAO{

	@Override
	public List<SkuItems> findAll(String chainSkuId, int pageNumber, int maxPageRow) {
		String sql = "select * from chain_sku_items where is_delete=? and chain_sku_id=? order by created_time desc";

		StatementParameter param = new StatementParameter();
		param.setInt(IsDelete.NO.toIntValue());
		param.setString(chainSkuId);

		return queryForPagingList(sql.toString(), SkuItems.class, param, pageNumber, maxPageRow);
	}

	@Override
	public int getTotalCount(String chainSkuId) {
		String sql = "select count(id) from chain_sku_items where is_delete=? and chain_sku_id=?";

		StatementParameter param = new StatementParameter();
		param.setInt(IsDelete.NO.toIntValue());
		param.setString(chainSkuId);

		return queryForInt(sql, param);
	}

	@Override
	public int queryNameIsExit(String chainSkuId, String standard) {
		String sql = "select count(id) from chain_sku_items where is_delete=? and chain_sku_id=? and standard=?";

		StatementParameter param = new StatementParameter();
		param.setInt(IsDelete.NO.toIntValue());
		param.setString(chainSkuId);
		param.setString(standard);

		return queryForInt(sql, param);

	}
	
	@Override
	public List<SkuItems> getAll(String chainSkuId){
		StringBuffer sql=new StringBuffer();
		sql.append("select * from chain_sku_items where is_delete=? and chain_sku_id=?");
		
		StatementParameter param=new StatementParameter();
		param.setInt(IsDelete.NO.toIntValue());
		param.setString(chainSkuId);
		
		return queryForList(sql.toString(),SkuItems.class,param);
	}
	
	@Override
	public int queryGoodsAboutSkuItemsCount(String chainSkuItemsId){
		StringBuffer sql=new StringBuffer();
		sql.append("select count(*) from goods_sku_items where sku_items_id=?");
		
		StatementParameter param=new StatementParameter();
		param.setString(chainSkuItemsId);
		
		return queryForInt(sql.toString(),param);
	}

}
